/*
 * gameDeviceCallback.cpp
 *
 *  Created on: 24.02.2012
 *      Author: Caffeine
 */
#include "CGameDevice.h"
#include "IGameObject.h"
#ifdef __WINDOWS__
#include <windows.h>
#endif

#ifdef __LINUX__
#include <stdio.h>
#include <unistd.h>
#endif

CGameDevice*IGameObject::getParent(){

	return (parent);
}
IGameObject::IGameObject(CGameDevice*p):device(0),smgr(0){

	parent=p;
#ifdef __GAME__
	driver=0;
	guienv=0;
#endif
	;
}

IGameObject::~IGameObject() {

	;
}

irr::core::stringc IGameObject::getPathToResurce(){

	return (pathToResurce);
}

void IGameObject::destroy(){
	//
}

void IGameObject::init(){

	device=getParent()->getDevice();
	smgr=device->getSceneManager();
#ifdef __GAME__
	driver=device->getVideoDriver();
	guienv=device->getGUIEnvironment();
#endif
/*
#ifdef __WIN32__
	char lp[MAX_PATH];
	DWORD length=GetModuleFileName(GetModuleHandle(NULL), lp,MAX_PATH);
	lp[length]=char(0);
	irr::core::stringc path=lp;

	irr::s32 p=path.findLast('\\');
	if (p>=0){
		pathToResurce=path.subString(0,p+1);
	}
	device->getFileSystem()->changeWorkingDirectoryTo(pathToResurce);
#endif

#ifdef __LINUX__
    char buf[PATH_MAX];
    readlink("/proc/self/exe", buf, sizeof(buf));
    irr::core::stringc path=buf;
	irr::s32 p=path.findLast('/');
	if (p>=0){
		pathToResurce=path.subString(0,p+1);
		device->getFileSystem()->changeWorkingDirectoryTo(pathToResurce);
	}
	//printf("path=%s\n",pathToResurce.c_str());
	//pathToResurce="/home/caffeine/Dropbox/PROG/game/Debug/";
#endif

#ifdef __ANDROID__
	#error write here a method for obtaining the path to resources for Android
#endif

#ifdef __IPHONE__
	#error write here a method for obtaining the path to resources for IPhone
#endif

	//device->getFileSystem()->addFolderFileArchive(pathToResurce.c_str(),false,false);
	 */
	;
}
